

import 'package:flutter/material.dart';
import 'package:flutter_trip/models/common_model.dart';
import 'package:flutter_trip/models/grid_nav_model.dart';
import 'package:flutter_trip/models/sales_box_model.dart';
import 'package:flutter_trip/widget/webview.dart';

class SalesBox extends StatelessWidget{
  final SalesBoxModel salesBox;
  final String name;

  SalesBox(this.salesBox,{this.name='xiaoming'});

  @override
  Widget build(BuildContext context) {
     return Container(
       decoration: BoxDecoration(
           color: Colors.white,

       ),
       child:_items(context),
     );
  }
  
  _items(BuildContext context){
    if(salesBox == null) return null;
    List<Widget>items =[];
//    for(CommonModel m in SubNavList){
//      print(m);
//      items.add(_item(context, m));
//    }
    //bool isBig,bool left,bool isLast
    items.add(_doubleItetms(context, salesBox.bigCard1, salesBox.bigCard2, true,false));
    items.add(_doubleItetms(context, salesBox.smallCard1, salesBox.smallCard1, false,false));
    items.add(_doubleItetms(context, salesBox.smallCard3, salesBox.smallCard4, false,true));

    return Column(
      children:[
        Container(
          height: 44,
          margin: EdgeInsets.only(left: 10),
          decoration: BoxDecoration(
            border: Border(bottom: BorderSide(width: 1,color: Color(0xfff2f2f2)))
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Image.network(salesBox.icon,height: 15,fit: BoxFit.fill,),
              Container(
                padding: EdgeInsets.fromLTRB(10, 1, 8, 1),
                margin: EdgeInsets.only(right: 7),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(12),
                  gradient: LinearGradient(
                      colors: [Color(0xffff4e63),Color(0xffff6cc9)],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight

                  ),

                ),
                child: GestureDetector(
                  onTap: (){

                    Navigator.push(context, MaterialPageRoute(builder: (context)=>MyWebView(salesBox.moreUrl, '0xffff4e63', '', false)));

                  },
                  child: Text('获取更多福利->',style: TextStyle(
                      color: Colors.white,
                      fontSize: 12
                  ),
                  ),

                ) ,
              ),

            ],
          ),
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: items.sublist(0,1),

        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: items.sublist(1,2),

        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: items.sublist(2,3),

        )
      ]
    );

  }
  Widget _doubleItetms(BuildContext context,CommonModel leftModel,CommonModel rightModel,bool isBig,bool isLast){

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,//排列方式
      children: [
        _item(context, leftModel, isBig,true, isLast),
        _item(context, rightModel, isBig, false, isLast),

      ],
    );

  }
  Widget _item(BuildContext context,CommonModel model,bool isBig,bool left, bool isLast){
    BorderSide borderSide = BorderSide(
        width: 0.8,
    color: Color(0xfff2f2f2f2)
    );
      return  GestureDetector(
        onTap: (){
          Navigator.push(context, MaterialPageRoute(builder: (context)=>MyWebView(model.url, model.statusBarColor, model.title, model.hideAppBar)));
        },
        child: Container(
          decoration: BoxDecoration(
              border:Border(right: left?borderSide:BorderSide.none,
                  bottom: isLast?BorderSide.none:borderSide)

          ),
          child: Image.network(
            model.icon,
            width: MediaQuery.of(context).size.width/2-10,
            height: isBig?129:80,
            fit: BoxFit.fill,
          ),
        ),
      )
      ;
  }


}